<template>
	<div style="margin-right: 30px">
		<el-form ref="formObj" :model="wyform" label-width="100px">
			<el-form-item label="名称" prop="name">
				<el-input placeholder="请输入区域名称" v-model="wyform.name"></el-input>
			</el-form-item>
			<el-form-item label="地址" prop="address">
				<el-input placeholder="请输入区域地址" v-model="wyform.address"></el-input>
			</el-form-item>
			
			<el-form-item>
				<el-button type="primary" plain :icon="Save" @click="save">保存</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script setup>
import Save from '@/components/icons/save.vue'
import { ref,reactive } from 'vue'
import { get,post } from '@/plugins/axios'
import { _axios } from '@/plugins/axios';
import url from './util'
const emits = defineEmits(['update:show','getTableData'])
const props = defineProps(['id'])


const formObj = ref()
const wyform = reactive({
  id: null,
  name: '',
  address: '',
})

function save(){
	post(props.id ? url.update : url.add,wyform,content =>{
		emits('update:show',false)
		emits('getTableData')
	},formObj)
}	
function getById(){
	get('/region/getById',{ id:props.id },content => {
		for(const key in wyform){
			if(Object.prototype.hasOwnProperty.call(content,key) ) 
			{
				wyform[key] = content[key]
			}
		}
		console.dir(wyform)
	})
}
if(props.id){
	wyform.id = props.id
	getById()
}

</script>

<style>
</style>